package com.bigfish.gbs.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * restful api文档
 * swagger2配置 默认地址http://localhost:8080/swagger-ui.html
 * Created by Joycessh
 * 11/29/18 11:09 AM
 */
@WebAppConfiguration  //如果项目中引入了junit，使用@WebAppConfiguration, 没有引入junit，使用@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.bigfish.gbs.controller"))
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("ssm-gbs:"+" Restful APIs")
                .description("restful apis docs")
                .termsOfServiceUrl("https://gitee.com/Jnbzmx/ssm-gbs.git").version("1.0").build();
    }

}
